package com.wowudi.controller;

import com.wowudi.dto.Result;
import com.wowudi.entity.House;
import com.wowudi.service.HouseService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@Api(tags = "住院管理")
@RequestMapping("api/hosp/house")
public class HouseController {

    @Autowired
    private HouseService houseService;

    @ApiOperation(value = "查询所有病房")
    @GetMapping("getHouse")
    public Result getHouse(){
        List<House> houseList = houseService.findHouseAll();
        Result result = new Result();
        result.setData(houseList);
        return result;
    }


    @ApiOperation(value = "添加病房")
    @PostMapping("addHouse")
    public Result addHouse(@RequestBody House house){
        int i = houseService.addHouse(house);
        Result result = new Result();
        if (i==1){
            result.setMessage("添加病房成功！");
        }else{
            result.setMessage("系统繁忙！！");
            result.setCode(500);
        }
        return result;
    }


    @ApiOperation(value = "修改病房")
    @PostMapping("updateHouse")
    public Result updateHouse(@RequestBody House house){
        int i = houseService.updateHouse(house);
        Result result = new Result();
        if (i==1){
            result.setMessage("修改病房成功！");
        }else{
            result.setMessage("系统繁忙！！");
            result.setCode(500);
        }
        return result;
    }

}
